using System.Collections.Generic;
using System;
using blog.DAL;
using blog.Models;

namespace blog.BLL {
    public class UserBLL {
        public static List<UsersModel> getAll () {
            return UserDAL.getAll ();
        }

        public static List<UsersModel> getPageList(int pageNum = 1, int pageSize = 10) {
            int limit = pageSize;
            int offset = (pageNum - 1) * pageSize;
            return UserDAL.getAll(limit, offset);
        }

        public static int totalCount() {
            return UserDAL.totalCount();
        }

        public static bool addUser (UsersModel model) {
            bool result = UserDAL.insert (model);

            return result;
        }

        public static bool saveUser(UsersModel model) {
            bool result = UserDAL.update(model);

            return result;
        }

        public static UsersModel findByAccount(string account) {
            UsersModel user = UserDAL.findOne("account", account);
            return user;
        }

        public static UsersModel findById(int id) {
            UsersModel user = UserDAL.findOne("id", id);
            return user;
        }

        public static bool deleteUser(int id) {
            return UserDAL.delete(id) > 0;
        }
    }
}